package com.example.stock.controller;

import com.example.stock.service.ArticleDataService;
import com.example.stock.service.GBStaService;
import com.example.stock.service.impl.GBStaServiceImpl;
import com.example.stock.util.Result;
import com.example.stock.util.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin(origins = "*")
@RequestMapping("article")
@RestController
public class ArticleController {

    @Autowired
    ArticleDataService articleDataService;

    /**
     * 获取所有文章的作者的接口
     *
     * @return 返回所有作者的结果
     */
    @GetMapping("author")
    Result authors(){
        return ResultGenerator.genSuccessResult(articleDataService.getArticleListBySource().keySet());
    }

    /**
     * 根据作者查询文章数据
     * @param author 作者
     * @return 结果
     */
    @GetMapping("author/{author}")
    Result index(@PathVariable String author) {
        return ResultGenerator.genSuccessResult(articleDataService.getArticleListBySource().get(author));
    }


    /**
     * 获取标签列表
     *
     * @return Result 返回标签列表结果
     */
    @GetMapping("tags")
    Result getTags(){
        return ResultGenerator.genSuccessResult(articleDataService.getArticleGroupByTag().keySet());
    }


    /**
     * 根据标签获取文章列表
     * @param tag 标签
     * @return 结果对象
     */
    @GetMapping("tags/{tag}")
    Result getTagArticle(@PathVariable String tag) {
        // 按日期排序并返回成功结果对象
        return ResultGenerator.genSuccessResult( articleDataService.getTagArticle(tag));
    }

    @GetMapping("lasted")
    Result lastedArticle(){
        return ResultGenerator.genSuccessResult(articleDataService.getLatestArticle());
    }

    @Autowired
    GBStaService gbStaService;

    @GetMapping("test/{stock}")
    Result test(@PathVariable String stock){
        return ResultGenerator.genSuccessResult(gbStaService.getDurGtList(GBStaServiceImpl.GB_60W_K, 60));
    }
}
